routine { }

Documentation for routine { } assembled from the following types:

language documentation Operators

From Operators

(Operators) term { }

Block or Hash constructor.

If the content is empty, or contains a single list that starts with a Pair literal or %-sigiled variable, and the $_ variable or placeholder parameters are not used, the constructor returns a Hash. Otherwise it constructs a Block.

To force construction of a Block, follow the opening brace with a semicolon. To always ensure you end up with a Hash, you can use %( ) coercer or hash routine instead:

{}.^name.say;        # OUTPUT: «Hash␤» 
{;}.^name.say;       # OUTPUT: «Block␤» 
 
{:$_}.^name.say;     # OUTPUT: «Block␤» 
%(:$_).^name.say;    # OUTPUT: «Hash␤» 
hash(:$_).^name.say# OUTPUT: «Hash␤»

language documentation Operators

From Operators

(Operators) postcircumfix { }

sub postcircumfix:<{ }>(%container**@key,
                        :$k:$v:$kv:$p:$exists:$delete)

Universal interface for associative access to zero or more elements of a %container, a.k.a. "hash indexing operator".

my %color = kiwi => "green"banana => "yellow"cherry => "red";
say %color{"banana"};                 # OUTPUT: «yellow␤» 
say %color{"cherry""kiwi"}.perl;    # OUTPUT: «("red", "green")␤» 
say %color{"strawberry"}:exists;      # OUTPUT: «False␤» 
 
%color{"banana""lime"} = "yellowish""green";
%color{"cherry"}:delete;
say %color;             # OUTPUT: «banana => yellowish, kiwi => green, lime => green␤»

See postcircumfix < > and postcircumfix « » for convenient shortcuts, and Subscripts for a more detailed explanation of this operator's behavior and how to implement support for it in custom types.